<?php

//小心执行,会清理upload中的无用图片.
include_once '../../config.inc.php';
$eve = isset($_POST['eve']) && !empty($_POST['eve']) ? $_POST['eve'] : 0;
//判断一下带参数才执行,不然乱搞了...
if ($eve == 1 && $adminId > 0) {
	$dir = "../../upload/";

	$folder = opendir($dir);
	$n = 0;
	while ($f = readdir($folder)) {
		if ($f <> "." && $f <> ".." && $f != "good_001.gif") {
			$sql = 'select gid from kp_goods where gphoto like \'%' . $f . '%\'';
			$rs = $pdo -> query($sql);

			//if (mysql_num_rows($rs) == 0) {
			if ($rs -> rowCount() == 0) {
				unlink($dir . $f);
				$n++;
			}
		}
	}
	if ($n != 0) {
		//返回成功
		echo '1';
	} else {
		echo '完成:不需要优化!';
		//不需要优化
	}
}
?>